<template>
			<view class="column-css">
				<view class="row-css" style="align-items: center;padding: 20rpx;background: #FFFFFF;justify-content:space-between" v-if="etpName"
					>
					<view class="" @click="onCarrier">
						<image style="width: 20rpx;height: 21rpx;padding-right: 10rpx;" mode="aspectFit"
							src="/static/icon_carrier.png"></image>
						{{ etpName }}
					</view>
				</view>
				<view style="padding: 20rpx;">进行中的任务</view>
				<block v-for="(item, index) in list" :key="index">
					<view style="border-radius: 10rpx;background: #FFFFFF;margin: 10rpx;">
						<view class="row-css" style="padding: 20rpx 10rpx;">
							{{ item.billNo }}
							<!-- | 辽HK4766 -->
						</view>
						<view class="column-css"
							style="margin: 10rpx;border-radius: 10rpx;background: #F7F7F7;padding: 20rpx;">
							<view class="row-css" style="align-items: center;">
								<view class="view-rodio" style="background: #C8E9CA;">
									<view class="view-rodio-ativc" style="background: #81D588;"></view>
								</view>
								{{ item.shippingCity }}
							</view>
							<image style="width: 20rpx;height: 21rpx;padding: 30rpx 0;margin-left: 5rpx;"
								mode="aspectFit" src="/static/icon_carrier_h.png"></image>
							<view class="row-css" style="align-items: center;">
								<view class="view-rodio" style="background: #F8C9AA;">
									<view class="view-rodio-ativc" style="background: #FB8536;"></view>
								</view>
								{{ item.receiptCity }}
							</view>
						</view>
						<view class="row-css"
							style="text-align: right;margin: 30rpx 10rpx;padding-bottom: 30rpx;">
							<view class="view-deltail"
								style="flex: 1;background: #FB8536;" @click="onOrders(item)" v-if="item.orderFormStatus === '1'">签约</view>
								<view class="view-deltail"
									style="flex: 1;background: #e7e7e7; color: #555;" v-else>已签约</view>
						</view>
					</view>
				</block>
				
				<uni-popup ref="orderPop" type="center">
							<view class="unipop__ui_body">
									<view class="unipop__ui_tit">签约提示</view>
									
									<view class="unipop__ui_cnt">
										<view style="color: #555;">
											<!-- <checkbox :checked="isChecked" style="transform:scale(0.7)" @click="checkbox()"></checkbox> -->
											按平台签约规定，承运接单时需签署<text @click="openUrl(signLocalUrl)" style="color: #FB8536;">《水路运输货物合同》</text>
											<text @click="openUrl(signPayLocalUrl)" style="color: #FB8536;" v-if="signObj.entrustPayee == 1">、《收款账号信息确认书》</text>
										</view>
										
									</view>
									<view class="unipop__ui_btns">
										<view class="btn btn-default" @click="close('orderPop')">
											取消
										</view>
										<view class="btn" style="color: #FB8536;" @click="confirmOrder">
											签约
										</view>
									</view>
							</view>
						</uni-popup>
			</view>
</template>

<script>
	import permision from "@/js_sdk/wa-permission/permission.js"
	import { URL1 } from "@/config/api.js"
	export default {
		props: {
			list: {
				type: Array,
				default: function() {
					return []
				}
			},
			etpName: String,
			shipInfo: {
				type: Object,
				default: function() {
					return {}
				}
			}
		},
		data() {
			return {
				count: 1,
				isChecked: false,
				waybillId: '',
				signObj: {},
				signTo: false
			}
		},
		created() {
			
		},
		methods: {
			onCarrier() {
				uni.navigateTo({
					url: '/pages/ship/task/carrier'
				})
			},
			onOrders(item) {
				this.isChecked = false;
				this.waybillId = item.waybillId;
				this.signLocalUrl = item.signLocalUrl;
				this.signPayLocalUrl = item.signPayLocalUrl;
				this.$refs['orderPop'].open();
				this.signObj = item
			},
			checkbox() {
				this.isChecked = !this.isChecked
			},
			close(name) {
				this.$refs[name].close()
			},
			confirmOrder() {
				
				let that = this
				// 认证流程
				that.close('orderPop')
				if (this.shipInfo.platformDriverLiveStatus === '0') {
					uni.showModal({
						title: '认证提示',
						content: '您尚未完成E签宝平台个人身份认证，请完成认证后继续签约',
						confirmText: '去认证',
						success(result) {
							if (result.confirm) {
								that.goAuth()
							}
						}
					})
					return
				}
				// e签宝
				that.wxRequest({
					url: `${this.API1}/seal/driverNotify/authSign`,
					method: 'POST',
					data: {
						mobile: uni.getStorageSync(that.DATA_KEY.userInfo).captainPhone,
						driverId: uni.getStorageSync(that.DATA_KEY.userInfo).driverId,
						"authType": "2",
						//#ifdef MP-WEIXIN
						redirectUrl:""
						//#endif
						//#ifdef APP-PLUS
						// redirectUrl:"y2t://app/realBack"
						redirectUrl: URL1 + "/sign/sign_reback_home.html"
						//#endif
					},
					title: '加载中...',
					success: function(res) {
						console.log(res.data, '111111111111')
						let url = ""
						//#ifdef MP-WEIXIN
						url = res.data.data
						//#endif
						// #ifdef APP-PLUS
						url = res.data.data
						// #endif
						///seal/driverNotify/authSign  判断用户是否认证  code = 0未认证，1已认证
						if (res.data.code == 0) {
							uni.showModal({
								title: '提示',
								content: '您尚未完成E签宝平台个人身份认证，请完成认证后继续签约',
								confirmText: '去认证',
								success: function(res) {
									if (res.confirm) {
										uni.setStorageSync(that.DATA_KEY.shipSignFlag, true);
										// #ifdef APP-PLUS
										switch (uni.getSystemInfoSync().platform) {
											case 'android':
												permision.requestAndroidPermission(
													"android.permission.RECORD_AUDIO")
												permision.requestAndroidPermission(
													"android.permission.CAMERA").then((e) => {
												if (e === -1) {
													uni.showToast({
														title: "您已经永久拒绝摄像头权限，请在应用设置中手动开启",
														icon: "none"
													})
												} else if (e === 0) {
													uni.showToast({
														title: "您拒绝了摄像头授权",
														icon: "none"
													})
												} else if (e === 1) {
													
													uni.navigateTo({
														url: '/pages/personal/webview?url=' +encodeURIComponent(url)
													})
												} else {
													uni.showToast({
														title: "授权返回值",
														icon: "none"
													})
												}
											})
												break;
											case 'ios':
												uni.navigateTo({
													url: '/pages/personal/webview?url=' +encodeURIComponent(url)
												})
													
											// 	permision.judgeIosPermission("record")
											// 	permision.judgeIosPermission("camera").then((e) => {
											// 	if (e === -1) {
											// 		uni.showToast({
											// 			title: "您已经永久拒绝摄像头权限，请在应用设置中手动开启",
											// 			icon: "none"
											// 		})
											// 	} else if (e === 0) {
											// 		uni.showToast({
											// 			title: "您拒绝了摄像头授权",
											// 			icon: "none"
											// 		})
											// 	} else if (e === 1) {
											// 		uni.navigateTo({
											// 			url: '/pages/personal/webview?url=' +encodeURIComponent(url)
											// 		})
											// 	} else {
											// 		uni.showToast({
											// 			title: "授权返回值",
											// 			icon: "none"
											// 		})
											// 	}
											// })
											break;
							}
										// #endif
				
										// #ifdef MP-WEIXIN
										uni.navigateTo({
											url: '/pages/personal/webview?url=' +
												encodeURIComponent(url)
										})
										
										// #endif
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						} else if (res.data.code == 1) {
							//已实名认证后，调取签署接口生成链接跳转到链接地址签署合同
							that.wxRequest({
								url: `${that.API1}/seal/driverNotify/fileSign`,
								method: 'POST',
								data: {
									mobile: uni.getStorageSync(that.DATA_KEY.userInfo).captainPhone,
									driverId: uni.getStorageSync(that.DATA_KEY.userInfo).driverId,
									loadingBillNo: that.signObj.billNo,
									type: '6',
									"authType":"2",
									"onOff": (that.signObj.entrustPayee == 1) ? '1' : '0',
									"onOffVos": (that.signObj.entrustPayee == 1) ? [
										{
											"type": "6",
											"billNo": that.signObj.billNo
										},
										{
											"type": "7",
											"billNo": that.signObj.payOrderNo
										}
									] : undefined,
									//#ifdef MP-WEIXIN
									redirectUrl:""
									//#endif
									//#ifdef APP-PLUS
									// redirectUrl:"y2t://app/realBack"
									redirectUrl: URL1 + "/sign/sign_reback_home.html"
									//#endif
								},
								title: '加载中...',
								success: function(res) {
									console.log(res,11111)
									uni.setStorageSync(that.DATA_KEY.shipSignFlag, true);
									let urls = ""
									//#ifdef MP-WEIXIN
									urls = res.data.data
									//#endif
									//#ifdef APP-PLUS
									urls = res.data.data
									// #endif
									// #ifdef APP-PLUS
									console.log(urls)
									console.log(uni.getSystemInfoSync().platform)
									switch (uni.getSystemInfoSync().platform) {
										case 'android':
											permision.requestAndroidPermission(
												"android.permission.RECORD_AUDIO")
											permision.requestAndroidPermission(
												"android.permission.CAMERA").then((e) => {
												if (e === -1) {
													uni.showToast({
														title: "您已经永久拒绝摄像头权限，请在应用设置中手动开启",
														icon: "none"
													})
												} else if (e === 0) {
													uni.showToast({
														title: "您拒绝了摄像头授权",
														icon: "none"
													})
												} else if (e === 1) {
													
													uni.navigateTo({
														url: '/pages/personal/webview?url=' +encodeURIComponent(urls)
													})
												} else {
													uni.showToast({
														title: "授权返回值",
														icon: "none"
													})
												}
											})
											break;
										case 'ios':
										console.log()
											uni.navigateTo({
												url: '/pages/personal/webview?url=' +encodeURIComponent(urls)
											})
											// permision.judgeIosPermission("record")
											// permision.judgeIosPermission("camera").then((e) => {
											// 	console.log(e)
											// 	if (e === -1) {
											// 		uni.showToast({
											// 			title: "您已经永久拒绝摄像头权限，请在应用设置中手动开启",
											// 			icon: "none"
											// 		})
											// 	} else if (e === 0) {
											// 		uni.showToast({
											// 			title: "您拒绝了摄像头授权",
											// 			icon: "none"
											// 		})
											// 	} else if (e === 1) {
											// 		uni.navigateTo({
											// 			url: '/pages/personal/webview?url=' +encodeURIComponent(urls)
											// 		})
											// 	} else {
											// 		uni.showToast({
											// 			title: "授权返回值",
											// 			icon: "none"
											// 		})
											// 	}
											// })
											break;
									
									}
									
									// #endif
									// #ifdef MP-WEIXIN
									uni.navigateTo({
										url: '/pages/middle/bizpage?url=' +encodeURIComponent(urls)
									})
									// #endif
								}
							})
						}
					},
					fail(err) {
						console.log(err)
					}
				})
				
				
				// if (!this.isChecked) {
				// 	uni.showToast({
				// 		title: '请点击同意签订该合约《船运运输协议书》',
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				// this.close('orderPop');
				// let that = this;
				// that.wxRequest({
				// 	url: `${that.API}/captainApp/updateOrderFormStatus?waybillId=` + this.waybillId,
				// 	method: 'POST',
				// 	data: {},
				// 	title: '加载中...',
				// 	success: res => {
				// 		if (res.data.code == 0) {
				// 			uni.showToast({
				// 				title: '接单成功',
				// 				icon: 'none'
				// 			})
				// 			that.$emit('orderSuccess')
				// 		}
				// 	}
				// })
			},
			openUrl(data) {
				if (!data) return;
				uni.showLoading({
					title: '加载中...'
				})
				uni.downloadFile({
					url: data, //下载资源的url
					success: function(res) {
						const filePath = res
						.tempFilePath; //tempFilePath临时文件路径，下载后的文件会存储到一个临时文件
						//新开页面打开文档，支持格式：doc, xls, ppt, pdf, docx, xlsx, pptx。
						uni.openDocument({
							filePath: filePath, //文件路径，可通过 downFile 获得
							showMenu: true, //表示右上角是否有转发按钮
							fileType: 'pdf', //文件类型，指定文件类型打开文件，有效值 doc, xls, ppt, pdf, docx, xlsx, pptx，支付宝小程序仅支持pdf
							success: function(res) {
								uni.hideLoading();
								console.log('打开文档成功');
							}
						});
					}
				});
			},
			async goAuth() {
				const result = await this.getDriverIdCardInfo();
				this.accessToken = result.data.accessToken;
				const result2 = await this.getFaceQRCode(result.data);
				let orderNumber = result2.data.orderNumber;
				this.orderNumber = orderNumber;
				// const result3 = await this.savePlatformDriverLive(orderNumber)
				let that = this
				// #ifdef APP-PLUS
				plus.share.getServices(
					function(res) {
						uni.setStorageSync(that.DATA_KEY.shipAuthFlag, true);
						var sweixin = null;
						console.log(res);
						for (var i = 0; i < res.length; i++) {
							var t = res[i];
							console.log(t);
							if (t.id == 'weixin') {
								sweixin = t;
							}
						}
						if (sweixin) {
							console.log('dddd=', 'a=' + sweixin + '=b');
							sweixin.launchMiniProgram({
								// id: 'gh_cec8224b00da',
								id: 'gh_45eec401ff1c',
								type: 0, //0-正式版 1.测试版，2，体验版
								path: 'pages/verify/info/index?id=' + orderNumber
							});
						}
					},
					function(res) {
						console.log(JSON.stringify(res));
					}
				);
				// #endif
				
				// #ifdef MP-WEIXIN
				uni.navigateToMiniProgram({
					// appId: 'wxfd2861dc1c86b3a0',
					appId: 'wxfc1e27e05fdd062b',
					path: 'pages/verify/info/index?id=' + orderNumber,
					envVersion: 'release',
					success(res) {
						uni.setStorageSync(that.DATA_KEY.shipAuthFlag, true);
						console.log('跳转成功');
					},
					fail(res) {
						console.log('跳转失败' + JSON.stringify(res));
					}
				});
				// #endif
			},
			getDriverIdCardInfo() {
				return new Promise((resolve, reject) => {
					let that = this;
					that.wxRequest({
						url: `${that.API}/captainApp/getCaptainIdCardInfo`,
						method: 'GET',
						title: '加载中...',
						success: res => {
							resolve(res.data)
						},
						fail: err => {
							reject(err)
						}
					});
				})
			},
			getFaceQRCode(data) {
				return new Promise((resolve, reject) => {
					let that = this;
					that.wxRequestData({
						url: `${that.API2}/api/face/getFaceQRCode?access_token=` + data.accessToken,
						method: 'POST',
						data: {
							companyTaxNumber: data.taxNumber,
							realName: data.CaptainName,
							idCard: data.idcard,
							idPhotoUp: data.idcard1Base64,
							idPhotoDown: data.idcard2Base64,
							callbackUrl: `${that.API}/driverService/isLivingBodyState`
						},
						success: res => {
							resolve(res.data)
						},
						fail: err => {
							reject(err)
						}
					})
				})
			},
			savePlatformDriverLive(orderNumber) {
				return new Promise((resolve, reject) => {
					let that = this;
					that.wxRequest({
						url: `${that.API}/captainApp/savePlatformDriverLive`,
						method: 'POST',
						data: {
							captainId: that.shipInfo.captain.captainId, //船长id
							orderNumber: orderNumber, //活体编号
							accessToken: that.accessToken
						},
						success: res => {
							resolve(res.data)
						},
						fail: err => {
							reject(err)
						}
					})
				})
			},
			async pageShow() {
				if(uni.getStorageSync(this.DATA_KEY.shipAuthFlag)) {
					await this.savePlatformDriverLive(this.orderNumber);
					// this.$emit('authSuccess')
					uni.setStorageSync(this.DATA_KEY.shipAuthFlag, false);
				}
				if (uni.getStorageSync(this.DATA_KEY.shipSignFlag)) {
					this.$emit('signSuccess')
					uni.setStorageSync(this.DATA_KEY.shipSignFlag, false);
				}
			}
		},
		beforeDestroy() {
			uni.setStorageSync(this.DATA_KEY.shipAuthFlag, false);
			uni.setStorageSync(this.DATA_KEY.shipSignFlag, false);
		}
	}
</script>

<style lang="scss" scoped>
	.row-desc {
		width: 80%;
		font-size: 24rpx;
		color: #999;
		// display: flex;
		justify-content: flex-end;
		align-items: center;
		text-align: center;
		image {
			width: 28rpx;
			height: 28rpx;
			margin-right: 10rpx;
			vertical-align:middle
		}
		view{
			display: inline-block;
			vertical-align:middle
		}
	}
	
	.column {
		display: flex;
		display: -webkit-flex;
		flex-direction: column;
		-webkit-flex-direction: column;
	}
	
	.row-css {
		display: flex;
		flex-direction: row;
	}
	
	.column-css {
		display: flex;
		flex-direction: column;
		.messagetips{
			float: right;
			position: relative;
			right: 0;
			text{
				padding: 10rpx;
				color: #FFFFFF;
				border-radius: 10rpx;
				right: 5rpx;
				background: #ff1606;
				position: absolute;
				font-size: 24rpx;
			}
			.tipstext{
				padding: 0rpx 8rpx;
				border-radius: 12rpx;
				right: -6rpx;
				top: -10rpx;
			}
		}
	}
	
	.code-view {
		width: 140rpx;
		text-align: center;
		padding: 12rpx 0;
		background: #ffffff;
		border: 1rpx solid #eeeeee;
		border-radius: 2rpx;
	
		width: 200rpx;
		text-align: center;
		font-size: 24rpx;
		margin-left: 20rpx;
		color: #ffffff;
		background: #2979ff;
		border-radius: 2rpx;
		padding: 15rpx 0;
	}
	
	.input-code {
		width: 180rpx;
		text-align: center;
		padding: 12rpx 0;
		background: #ffffff;
		border: 1rpx solid #eeeeee;
		border-radius: 2rpx;
	}
	
	.view-deltail {
		text-align: center;
		background: #2b7cff;
		padding: 20rpx 0;
		color: #ffffff;
		border-radius: 5rpx;
	}
	
	.car-view {
		flex-flow: wrap;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		justify-content: space-between;
	}
	
	.car-view-text {
		border-radius: 15rpx;
		margin: 10rpx;
		border: 1rpx solid #999999;
		padding: 5rpx 10rpx;
	}
	
	.view-rodio {
		display: flex;
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		margin-right: 10rpx;
	}
	
	.view-rodio-ativc {
		width: 15rpx;
		height: 15rpx;
		margin: 7.5rpx;
		border-radius: 50%;
	}
	
	.view-sold-real {
		width: 80%;
		border: 1rpx solid #DCDFE6;
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 18rpx 15rpx;
		justify-content: space-between;
	}
	
	uni-modal .uni-modal__bd {
		white-space: pre-wrap;
	}
	
	.button-view {
		width: 49%;
		justify-content: center;
		padding: 30rpx;
	}
	.popup4Tips{
		font-size: 24rpx;
		color: #494949;
		text-align: left;
		margin-top: 6rpx;
		width: 80%;
		text{
			color: #ff1606;
			padding-right: 10rpx;
		}
	}
	
	.unipop__ui_body {
			background-color: #fff;
			border-radius: 12px;
			text-align: center;
			position: relative;
		}
		@media screen and (min-width: 352px) {
			.unipop__ui_body {
				width: 320px;
			}
		}
		
		.unipop__ui_tit {
			padding: 32px 24px 16px;
			font-size: 17px;
			color: rgba(0, 0, 0, 0.9);
			font-weight: 700;
			font-size: 17px;
			line-height: 1.4;
			position: relative;
		}
		.unipop__ui_close {
			position: absolute;
			right: 15px;
			top: 15px;
			
		}
		.unipop__ui_cnt {
			padding: 0 24px;
			margin-bottom: 32px;
			font-size: 17px;
			line-height: 1.4;
			word-wrap: break-word;
			color: rgba(0, 0, 0, 0.5);
		}
		.unipop__ui_btns {
			display: flex;
			position: relative;
		}
		.unipop__ui_btns::after {
			content: " ";
			position: absolute;
			left: 0;
			top: 0;
			right: 0;
			height: 1px;
			border-top: 1px solid rgba(0,0,0,0.1);
			color: rgba(0,0,0,0.1);
			transform-origin: 0 0;
			transform: scaleY(0.5);
		}
		.unipop__ui_btns .btn {
			flex: 1;
			font-size: 17px;
			line-height: 1.4;
			font-weight: 600;
			color: #576b95;
			padding: 16px 23px;
			user-select: none;
			position: relative;
		}
		.unipop__ui_btns .btn.btn-default {
			color: rgba(0, 0, 0, 0.9);
		}
		.unipop__ui_btns .btn:first-child::after {
			display: none;
		}
		.unipop__ui_btns .btn::after {
			content: " ";
			position: absolute;
			left: 0;
			top: 0;
			width: 1px;
			bottom: 0;
			border-left: 1px solid rgba(0,0,0,0.1);
			color: rgba(0,0,0,0.1);
			transform-origin: 0 0;
			transform: scaleX(0.5);
		}
</style>